package com.petplanet.common.ui.theme

import android.os.Build
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.darkColorScheme
import androidx.compose.material3.dynamicDarkColorScheme
import androidx.compose.material3.dynamicLightColorScheme
import androidx.compose.material3.lightColorScheme
import androidx.compose.runtime.Composable
import androidx.compose.ui.platform.LocalContext

private val DarkColorScheme = darkColorScheme(
    primary = DarkPrimary,
    onPrimary = DarkOnPrimary,
    primaryContainer = DarkPrimaryVariant,
    onPrimaryContainer = DarkOnPrimaryContainer,
    inversePrimary = DarkPrimary,
    secondary = DarkSecondary,
    onSecondary = DarkOnSecondary,
    secondaryContainer = DarkSecondaryVariant,
    onSecondaryContainer = DarkOnSecondaryContainer,
    tertiary = DarkTertiary,
    onTertiary = DarkOnTertiary,
    tertiaryContainer = DarkTertiaryVariant,
    onTertiaryContainer = DarkOnTertiaryContainer,
    background = DarkBackground,
    onBackground = DarkOnBackground,
    surface = DarkSurface,
    onSurface = DarkOnSurface,
    surfaceVariant = DarkSurfaceVariant,
    onSurfaceVariant = DarkOnSurfaceVariant,
    surfaceTint = DarkSurfaceTint,
    inverseSurface = DarkInverseSurface,
    inverseOnSurface = DarkInverseOnSurface,
    error = DarkError,
    onError = DarkOnError,
    errorContainer = DarkErrorContainer,
    onErrorContainer = DarkOnErrorContainer,
    outline = DarkOutline,
    outlineVariant = DarkOutlineVariant,
    scrim = DarkScrim,
    surfaceBright = DarkSurface,
    surfaceContainer = DarkSurface,
    surfaceContainerHigh = DarkSurface,
    surfaceContainerHighest = DarkSurface,
    surfaceContainerLow = DarkSurface,
    surfaceContainerLowest = DarkSurface,
    surfaceDim = DarkSurface
)

// 定义亮色主题实例
private val LightColorScheme = lightColorScheme(
    primary = WarmPrimary,  // 主色
    onPrimary = WarmOnPrimary,  // 主色上的文字颜色
    primaryContainer = WarmPrimaryVariant,  // 主色容器颜色
    onPrimaryContainer = WarmOnPrimary,  // 主色容器上的文字颜色
    inversePrimary = WarmPrimary,  // 反转主色
    secondary = WarmSecondary,  // 次要颜色
    onSecondary = WarmOnSecondary,  // 次要颜色上的文字颜色
    onSecondaryContainer = WarmOnSecondary,  // 次要颜色容器上的文字颜色
    tertiary = WarmTertiary,  // 第三颜色
    onTertiary = WarmOnTertiary,  // 第三颜色上的文字颜色
    tertiaryContainer = WarmTertiaryContainer,  // 第三颜色容器
    onTertiaryContainer = WarmOnTertiaryContainer,  // 第三颜色容器上的文字颜色
    background = WarmBackground,  // 背景颜色
    onBackground = WarmOnBackground,  // 背景上的文字颜色
    surface = WarmSurface,  // 表面颜色
    onSurface = WarmOnSurface,  // 表面上的文字颜色
    surfaceVariant = WarmSurfaceVariant,  // 表面变体颜色
    onSurfaceVariant = WarmOnSurfaceVariant,  // 表面变体上的文字颜色
    surfaceTint = WarmSurfaceTint,  // 表面着色
    inverseSurface = WarmInverseSurface,  // 反转表面颜色
    inverseOnSurface = WarmInverseOnSurface,  // 反转表面上的文字颜色
    error = WarmError,  // 错误颜色
    onError = WarmOnError,  // 错误上的文字颜色
    errorContainer = WarmErrorContainer,  // 错误容器颜色
    onErrorContainer = WarmOnErrorContainer,  // 错误容器上的文字颜色
    outline = WarmOutline,  // 轮廓颜色
    outlineVariant = WarmOutlineVariant,  // 轮廓变体颜色
    scrim = WarmScrim,  // 遮罩颜色
    surfaceBright = WarmSurface,  // 亮表面颜色
    surfaceContainer = WarmSurface,  // 表面容器颜色
    surfaceContainerHigh = WarmSurface,  // 高表面容器颜色
    surfaceContainerHighest = WarmSurface,  // 最高表面容器颜色
    surfaceContainerLow = WarmSurface,  // 低表面容器颜色
    surfaceContainerLowest = WarmSurface,  // 最低表面容器颜色
    surfaceDim = WarmSurface  // 暗淡表面颜色
)

@Composable
fun PetPlanetTheme(
    darkTheme: Boolean = isSystemInDarkTheme(),
    // Dynamic color is available on Android 12+
    dynamicColor: Boolean = true,
    content: @Composable () -> Unit
) {
    val colorScheme = when {
        dynamicColor -> {
            val context = LocalContext.current
            if (darkTheme) dynamicDarkColorScheme(context) else dynamicLightColorScheme(context)
        }

        darkTheme -> DarkColorScheme
        else -> LightColorScheme
    }

    MaterialTheme(
        colorScheme = colorScheme,
        typography = Typography,
        content = content
    )
}
